console.log("进入role.js");
//加载所有的角色

//显示添加角色页面
    $(".addrole").on('click', function () {
        $(".loadRole").css('display','none');
        $(".addroleForm").css('display', 'block');

    });

//将添加的角色传给后端
    $(".addrolebtn").on('click', function () {
        console.log("进入添加角色页面");
        var roleId = $(".roleId").val().trim();
        var name = $(".name").val().trim();
        var description = $(".description").val().trim();
        var url = "http://localhost:8080/addRole";
        $.ajax({
            url: url,
            type: "post",
            data: {roleId: roleId, name: name, description: description},
            success: function (result) {
                $(".addroleForm").css('display',"none");
            },
            error: function () {
                alert("err");
            }
        })
    });

    //修改角色
    $(".modRole").on('click',function () {
        var roleId=$(this).attr("data-roleId");
        console.log(roleId);
        $(".loadRole").css('display','none');
        var url="http://localhost:8080/putRole?roleId="+roleId;
        $(".moddiv").load(url);
    });


    //删除角色
    $(".delRole").on('click',function () {
       var roleId=$(this).attr("data-roleId");
       var url="http://localhost:8080/delRole?roleId="+roleId;
       $.ajax({
           type: "DELETE",
           url:url,
           success:function (data) {
               if(data.status==1){
                   alert(data.msg);
               }else {
                   alert(data.msg);
               }
           },
           fail:function () {
               alert("服务器繁忙")
           },
           complete:function () {
               $("body").load("http://localhost:8080/role");
           }
       })
    });
